package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.qichacha.QiChaChaShixinList;
import com.ucredit.babel.common.model.third.qichacha.QiChaChaShixinListData;
import com.ucredit.babel.common.model.third.qichacha.QiChaChaShixinListRecord;
import com.ucredit.babel.common.model.third.tanzhi.TanZhiDataV2;
import com.ucredit.babel.common.model.third.tanzhi.TanZhiObject;
import com.ucredit.babel.common.model.third.tanzhi.TanZhiRecordV2;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 探知-联合建模
 *
 * @author xj
 */

public class TanZhiV2RecordParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 探知-联合建模
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        TanZhiRecordV2 obj = (TanZhiRecordV2) model;
        TanZhiDataV2 data = obj.getTanZhiDataV2() == null ? new TanZhiDataV2() : obj.getTanZhiDataV2();
        TanZhiObject info = data.getData() == null ? new TanZhiObject() : data.getData();

        StringBuilder sb = getBaseInfo(obj, successful);
        //m1逾期提醒事件累计次数
        sb.append(info.getEveSumsOverdueSumM1()).append(CRT001);
        //最近一次逾期提醒事件距当前时间天数
        sb.append(info.getLastTimeOverdueRemindLastToNowD()).append(CRT001);
        //m6逾期提醒平台累计次数
        sb.append(info.getPlatformInfosOverdueCountM6()).append(CRT001);
        //m1违约金额最大值等级
        sb.append(info.getMaxOverdueAmountLevelM1()).append(CRT001);
        //m1违约金额均值等级
        sb.append(info.getAveOverdueAmountLevelM1()).append(CRT001);
        //m1违约通知金额最大值等级
        sb.append(info.getMaxAllOverdueRemindAmtLevelM1()).append(CRT001);
        //m1违约通知金额均值等级
        sb.append(info.getAvgAllOverdueRemindAmtLevelM1()).append(CRT001);
        //m3逾期提醒事件累计次数
        sb.append(info.getEveSumsOverdueSumM3()).append(CRT001);
        //m6最大逾期时长等级
        sb.append(info.getRefInfosMaxOverdueDelayLevelM6()).append(CRT001);
        //最近3个月探真调用次数
        sb.append(info.getTanzhenCount().getInteger("m3")).append(CRT001);
        //最近6个月探真调用次数
        sb.append(info.getTanzhenCount().getInteger("m6")).append(CRT001);
        //m3逾期提醒平台累计次数
        sb.append(info.getPlatformInfosOverdueCountM3()).append(CRT001);
        //m3借贷类违约时长均值等级
        sb.append(info.getRefInfosAveOverdueDelayLevelM3()).append(CRT001);
        //m1逾期已还事件累计次数
        sb.append(info.getEveSumsOverdueRepaySumM1()).append(CRT001);
        //m1违约修复金额最大值等级
        sb.append(info.getRefInfosMaxOverdueRepayAmountLevelM1()).append(CRT001);
        //m6违约金额最大值等级
        sb.append(info.getMaxOverdueAmountLevelM6()).append(CRT001);
        //m6逾期提醒事件累计次数
        sb.append(info.getEveSumsOverdueSumM6()).append(CRT001);
        //m6最大借贷类逾期提醒金额等级
        sb.append(info.getRefInfosMaxAllOverdueRemindAmtLevelM6()).append(CRT001);
        //最近一次违约修复距今天数
        sb.append(info.getLastTimeOverdueRepayLastToNowD()).append(CRT001);
        //m3逾期已还平台累计次数
        sb.append(info.getPlatformInfosOverdueRepayCountM3()).append(CRT001);
        //m6最大逾期已还时长等级
        sb.append(info.getRefInfosMaxOverdueRepayDelayLevelM6()).append(CRT001);
        //m3逾期已还事件累计次数
        sb.append(info.getEveSumsOverdueRepaySumM3()).append(CRT001);
        //m6逾期已还平台累计次数
        sb.append(info.getPlatformInfosOverdueRepayCountM6()).append(CRT001);
        //m6逾期已还事件累计次数
        sb.append(info.getEveSumsOverdueRepaySumM6()).append(CRT001);

        key.set(getKey());
        val.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_tanzhi_v2_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.TANZHI_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "探知-联合建模";
    }
}
